package io.renren.modules.generator.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.LeaveinfoEntity;
import io.renren.modules.generator.service.LeaveinfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-10-13 22:43:28
 */
@RestController
@RequestMapping("/generator/leaveinfo")
public class LeaveinfoController {
	@Autowired
	private LeaveinfoService leaveinfoService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("generator:leaveinfo:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<LeaveinfoEntity> leaveinfoList = leaveinfoService.queryList(query);
		int total = leaveinfoService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(leaveinfoList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{leaveno}")
	@RequiresPermissions("generator:leaveinfo:info")
	public R info(@PathVariable("leaveno") String leaveno){
		LeaveinfoEntity leaveinfo = leaveinfoService.queryObject(leaveno);
		
		return R.ok().put("leaveinfo", leaveinfo);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("generator:leaveinfo:save")
	public R save(@RequestBody LeaveinfoEntity leaveinfo){
		leaveinfoService.save(leaveinfo);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("generator:leaveinfo:update")
	public R update(@RequestBody LeaveinfoEntity leaveinfo){
		leaveinfoService.update(leaveinfo);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("generator:leaveinfo:delete")
	public R delete(@RequestBody String[] leavenos){
		leaveinfoService.deleteBatch(leavenos);
		
		return R.ok();
	}
	
}
